﻿Namespace Prim.Makbuz
	Module Functions

		Function Bilgi(ByVal Token As Token, ByVal makbuzno As String) As Recordset
			Q("select distinct isyerino,islemtar,kaykul,bordrotar,bordro from shesk where makbuzno = @makbuzno union")
			Q("select distinct isyerino,islemtar,kaykul,bordrotar,bordro from sheskp where makbuzno = @makbuzno")
			Return Token.OpenSQL("*", makbuzno)
		End Function

		Function Primler(ByVal Token As Token, ByVal makbuzno As String) As Recordset
			Q("select rowid,isyerino,kimlik,pasaport,sno,(select rtrim(adi)+' '+rtrim(soyadi) from sgenel where sno = shesk.sno) as adi,pek,pogs,taksit,'' as prob")
			Q("from shesk where makbuzno = @makbuzno union all")
			Q("select rowid,isyerino,kimlik,pasaport,sno,rtrim(adi)+' '+rtrim(soyadi) as adi,pek,pogs,taksit,'P' from sheskp where makbuzno = @makbuzno order by kimlik")
			Return Token.OpenSQL("*", makbuzno)
		End Function

		Sub PrimIptal(ByVal Token As Token, ByVal shesk As String, ByVal sheskp As String, ByVal kaykul As String)
			Token.BeginTran()
			If shesk <> "" Then
				Q("insert into shesk (kimlik,pasaport,sno,isyerino,bordro,bordrotar,pek,pogs,makbuzno,kaykul,islemtar)")
				Q("select kimlik,pasaport,sno,isyerino,bordro,bordrotar,-pek,-pogs,makbuzno,@kaykul,getdate()")
				Q("from shesk where rowid in (" & shesk & ")")
				Token.ExecSQL("*", kaykul)
			End If
            If sheskp <> "" AndAlso Not (IsNothing(sheskp)) Then
                Q("insert into sheskp (kimlik,pasaport,sno,adi,soyadi,isyerino,bordro,bordrotar,pek,pogs,makbuzno,kaykul,islemtar)")
                Q("select kimlik,pasaport,sno,adi,soyadi,isyerino,bordro,bordrotar,-pek,-pogs,makbuzno,@kaykul,getdate()")
                Q("from sheskp where rowid in (" & sheskp & ")")
                Token.ExecSQL("*", kaykul)
            End If

			Token.CommitTran()
		End Sub

	End Module
End Namespace
